<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\admin\model\ExhibitionModel;

class Exhibition extends Common
{
	/**
	*	展会列表
	*/
	public function index()
	{
		$data = $this->request->param();
		$ExhibitionModel = new ExhibitionModel();

		$list = $ExhibitionModel->getExhibition($data);
		$this->assign('list',$list);
		$page = $list->render();
		$this->assign('page',$page);

		$this->assign('e_status',isset($data['e_status']) ? $data['e_status'] : '');
		$this->assign('e_name',isset($data['e_name']) ? $data['e_name'] : '');
		return $this->fetch();
	}

	/**
	*	添加展会
	*/
	public function add()
	{
		return $this->fetch();
	}

	/**
	*	添加展会提交
	*/
	public function addPost()
	{
		if($this->request->isPost()){
			$data = $this->request->param();

			$result = $this->validate($data,'ExhibitionValidate');
			if($result !== true){
				$this->error($result);
			}

			$ExhibitionModel = new ExhibitionModel();
			$list = $ExhibitionModel->addExhibition($data);

			if($list === 2){
				$this->success('添加成功');

			}elseif($list === 3){
				$this->error('已有一个发布的数据,请不要重复发');

			}else{

				$this->error('添加失败');
			}

		}
	}

	/**
	*	修改展会信息
	*/
	public function edit()
	{
		$data = $this->request->param();
		if($data){
			$ExhibitionModel = new ExhibitionModel();
			$list = $ExhibitionModel->getOne($data['id']);
			$this->assign('list',$list);
		}
		return $this->fetch();
	}

	/**
	*	修改展会信息提交
	*/
	public function editPost()
	{
		if($this->request->isPost()){
			$data = $this->request->param();

			$result = $this->validate($data,'ExhibitionValidate');
			if($result !== true){
				$this->error($result);
			}

			$ExhibitionModel = new ExhibitionModel();
			$list = $ExhibitionModel->editExhibition($data['id'],$data);

			if($list === 2){
				$this->success('修改成功');

			}elseif($list === 3){

				$this->error('修改失败');
			}

		}
	}

	/**
	*	删除展会信息提交
	*/
	public function delete()
	{
		
	}
}